home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1 / Nebula One.iso / Utilities / Workspace / Locus / Source / AtomList.m < prev    next >
Text File  |  1995-06-12  |  4KB  |  235 lines

  1.  
  2. /*
  3.     Copyright 1993  Jeremy Slade.
  4.  
  5.     You are free to use all or any parts of the Locus project
  6.     however you wish, just give credit where credit is due.
  7.     The author (Jeremy Slade) shall not be held responsible
  8.     for any damages that result out of use or misuse of any
  9.     part of this project.
  10.  
  11. */
  12.  
  13. /*
  14.     Project: Locus
  15.  
  16.     File: AtomList.m
  17.  
  18.     Description: See AtomList.h
  19.  
  20.     Original Author: Jeremy Slade
  21.  
  22.     Revision History:
  23.         Created
  24.             V.101    JGS    Fri Mar 12 23:51:47 GMT-0700 1993
  25.  
  26. */
  27.  
  28.  
  29. #import "AtomList.h"
  30. #import <appkit/Text.h> // For NXOrderStrings()
  31.  
  32.  
  33. @implementation AtomList
  34.  
  35.  
  36. // -------------------------------------------------------------------------
  37. //   Creating, Initializing
  38. // -------------------------------------------------------------------------
  39.  
  40.  
  41. + initialize
  42. {
  43.     [self setVersion:AtomList_VERSION];
  44.     return ( self );
  45. }
  46.  
  47.  
  48.  
  49. - initCount:(unsigned)num
  50. {
  51.     [super initCount:num];
  52.     return ( self );
  53. }
  54.  
  55.  
  56.  
  57. - free
  58. {
  59.     return ( [super free] );
  60. }
  61.  
  62.  
  63.  
  64. // -------------------------------------------------------------------------
  65. //   Manipulating Atoms by index
  66. // -------------------------------------------------------------------------
  67.  
  68.  
  69. - insertAtom:(NXAtom)a at:(unsigned)index
  70. {
  71.     return ( [super insertObject:(id)a at:index] );
  72. }
  73.  
  74.  
  75.  
  76. - addAtom:(NXAtom)a
  77. {
  78.     return ( [super addObject:(id)a] );
  79. }
  80.  
  81.  
  82.  
  83. - addAtomAlphabetically:(NXAtom)a
  84. {
  85.     unsigned int i = 0;
  86.     BOOL added = NO;
  87.     
  88.     // Find place to insert in list
  89.     for ( i=0; i<numElements; i++ ) {
  90.         if ( NXOrderStrings ( a, [self atomAt:i], NO, -1, NULL ) == -1 ) {
  91.             [self insertAtom:a at:i];
  92.             added = YES;
  93.             break;
  94.         }
  95.     }
  96.     
  97.     // Didn't come before any existing Atoms, add it to the end
  98.     if ( !added ) [self addAtom:a];
  99.     
  100.     return ( self );
  101. }
  102.  
  103.  
  104.  
  105. - removeAtomAt:(unsigned)index
  106. {
  107.     return ( [super removeObjectAt:index] );
  108. }
  109.  
  110.  
  111.  
  112. - removeLastAtom
  113. {
  114.     return ( [super removeLastObject] );
  115. }
  116.  
  117.  
  118.  
  119. - replaceAtomAt:(unsigned)index with:(NXAtom)newA
  120. {
  121.     return ( [super replaceObjectAt:index with:(id)newA] );
  122. }
  123.  
  124.  
  125.  
  126. - (NXAtom)atomAt:(unsigned)index
  127. {
  128.     return ( (NXAtom)[super objectAt:index] );
  129. }
  130.  
  131.  
  132.  
  133. - (NXAtom)lastAtom
  134. {
  135.     return ( (NXAtom)[super lastObject] );
  136. }
  137.  
  138.  
  139.  
  140. - (unsigned)count
  141. {
  142.     return ( [super count] );
  143. }
  144.  
  145.  
  146.  
  147. // -------------------------------------------------------------------------
  148. //   Manipulating Atoms by pointer
  149. // -------------------------------------------------------------------------
  150.  
  151.  
  152. - addAtomIfAbsent:(NXAtom)a
  153. {
  154.     return ( [super addObjectIfAbsent:(id)a] );
  155. }
  156.  
  157.  
  158.  
  159. - removeAtom:(NXAtom)a
  160. {
  161.     return ( [super removeObject:(id)a] );
  162. }
  163.  
  164.  
  165.  
  166. - (unsigned)indexOfAtom:(NXAtom)a
  167. {
  168.     return ( [super indexOf:(id)a] );
  169. }
  170.  
  171.  
  172.  
  173. // -------------------------------------------------------------------------
  174. //   Archiving
  175. // -------------------------------------------------------------------------
  176.  
  177.  
  178. - awake
  179. {
  180.     [super awake];
  181.     return ( self );
  182. }
  183.  
  184.  
  185.  
  186. - read:(NXTypedStream *)stream
  187. {
  188.     unsigned int count, i;
  189.     NXAtom *array;
  190.     
  191.     // First, let super do it's thing...
  192.     [super read:stream];
  193.     
  194.     // Then, read the number of Atoms in the list and set the capacity of
  195.     // the array
  196.     NXReadType ( stream, "i", &count );
  197.     [self setAvailableCapacity:count];
  198.     numElements = count;
  199.     
  200.     // Then read all of the Atoms
  201.     array = (NXAtom *)dataPtr;
  202.     for ( i=0; i<count; i++ ) NXReadType ( stream, "%", array++ );
  203.     
  204.     return ( self );
  205. }
  206.  
  207.  
  208.  
  209. - write:(NXTypedStream *)stream
  210. {
  211.     unsigned int count, i;
  212.     NXAtom *array;
  213.     
  214.     // First, set count to zero to make [super write:] think there is
  215.     // nothing to write...
  216.     count = numElements;
  217.     numElements = 0;
  218.     
  219.     // Now let super do it's thing...
  220.     [super write:stream];
  221.     
  222.     // Now we'll archive the Atoms ourselves
  223.     numElements = count;
  224.     NXWriteType ( stream, "i", &count );
  225.     array  = (NXAtom *)dataPtr;
  226.     for ( i=0; i<count; i++ ) NXWriteType ( stream, "%", array++ );
  227.     
  228.     return ( self );
  229. }
  230.  
  231.  
  232.  
  233. @end
  234.  
  235.